

import plugin from '../../../lib/plugins/plugin.js'
import common from "../../../lib/common/common.js"
import data from '../model/XiuxianData.js'
import config from "../model/Config.js"
import fs from "node:fs"

/**
 * 定时任务
 */

export class GamesTask extends plugin {
    constructor() {
        super({
            name: 'GamesTask',
            dsc: '定时任务',
            event: 'message',
            priority: 300,
            rule: [
                {
                    reg: '^#查询游戏任务$',
                    fnc: 'Gamestask'
                }
            ]
        });

        //获取配置信息
        this.set = config.getdefSet('task', 'GamesTask')

        /** 定时任务查询人物动作结束时间 */
        this.task = {
            cron: '0 */2 * * * ?',
            name: '查询人物动作是否完成',
            fnc: () => this.Gamestask()
        }
    }

    /** 查询人物动作是否完成 */
    async Gamestask() {
        //获取缓存中人物列表
        let playerList = [];
        let files = fs
            .readdirSync("./plugins/xiuxian-emulator-plugin/resources/data/xiuxian_player")
            .filter((file) => file.endsWith(".json"));
        for (let file of files) {
            file = file.replace(".json", "");
            playerList.push(file);
        }
    }


    /**
     * 推送消息，群消息推送群，或者推送私人
     * @param id
     * @param is_group
     * @returns {Promise<void>}
     */
    async pushInfo(id, is_group, msg) {
        if (is_group) {
            await Bot.pickGroup(id)
                .sendMsg(msg)
                .catch((err) => {
                    Bot.logger.mark(err);
                });
        }
        else {
            await common.relpyPrivate(id, msg);
        }
    }
}
